﻿@model PcaSocios.BOL.oVwCliente  

@{
    var X = Html.X();
}

@(
 X.GridPanel()
        .ID("GridClientes")
        .Title("Clientes")
        .Flex(1)
        .Store(
            X.StoreForModel()
                .ID("storeClientes")
                .Parameters(p =>
                {
                    p.Add(new StoreParameter() { Name = "filtro", Value = "App.filtro.getValue()", Mode = ParameterMode.Raw });
                })
                .Proxy(X.AjaxProxy()
                    .Url(Url.Action("GetList", "Cliente"))
                    .Reader(X.JsonReader().RootProperty("data"))
                )
                .RemoteSort(false)
                .PageSize(20)
        )
        .ColumnModel(
                X.Column().DataIndex(Model ,m => m.tipo_cliente).Text("Tipo").Width(80),
                X.Column().DataIndex(Model, m => m.tipo_documento_identidad).Text("Tipo doc.").Width(100),
                X.Column().DataIndex(Model,m=>m.numero_documento_identidad ).Text("N° doc.").Width(100),
                X.Column().DataIndex(Model,m=>m.nombre).Text("Nombre").Flex(1),
                X.Column().DataIndex(Model,m=>m.pais).Text("Pais").Width(70),
                X.Column().DataIndex(Model,m=>m.direccion).Text("Direccion").Flex(1),
                X.DateColumn().DataIndex(Model, m => m.fecha_registro).Text("Fecha registro").Format("dd MMMM yyyy").Align(Alignment.Center).Width(120),
                X.CommandColumn().Hideable(false).Text("Operaciones").Align(Alignment.Center)
                    .Commands(
                        X.GridCommand().CommandName("cmdEditar").ToolTip(t => t.Text = "Editar cliente").Icon(Icon.ApplicationEdit),
                        X.GridCommand().CommandName("cmdEliminar").ToolTip(t => t.Text = "Eliminar cliente").Icon(Icon.ApplicationDelete)
                    )
                    .DirectEvents(de =>
                    {
                        de.Command.Url = Url.Action("RunCommandGrid", "Cliente");
                        de.Command.ExtraParams.Add(new Parameter { Name = "commandName", Value = "command", Mode = ParameterMode.Raw });
                        de.Command.ExtraParams.Add(new Parameter { Name = "clienteId", Value = "record.data.cliente_id", Mode = ParameterMode.Raw });
                        de.Command.Before = "Ext.getBody().mask('Cargando...!', 'x-mask-loading');";
                        de.Command.Complete = "Ext.getBody().unmask();";
                        de.Command.Failure = "PcaGlobal.showError(result.msg);";
                    })
        )
        .TopBar(
            X.Toolbar()
                .Items(
                    X.Button()
                        .ID("btnNuevo")
                        .Text("Nuevo")
                        .Icon(Icon.Add)
                        .DirectEvents(de =>
                        {
                            de.Click.Url = Url.Action("FrmRegistrar", "Cliente");
                            de.Click.Failure = "PcaGlobal.showError(result.msg);";
                            de.Click.EventMask.ShowMask = true;
                            de.Click.EventMask.Msg = "Consultando...";
                        }),
                    X.ToolbarFill(),
                    X.TextField()
                        .ID("filtro")
                        .Width(250)
                        .EnableKeyEvents(true)
                        .EmptyText("Buscar...")
                        .Triggers(
                            X.FieldTrigger()
                                .Hidden(true)
                                .Icon(TriggerIcon.Clear)
                        )
                        .Listeners(l =>
                        {
                            l.KeyUp.Handler = @"if (Ext.isEmpty(App.filtro.getValue(), false)) {
                                                App.filtro.setValue('');
                                                App.filtro.getTrigger(0).hide();
                                            } else {
                                                App.filtro.getTrigger(0).show();
                                            }";
                            l.TriggerClick.Handler = @"App.filtro.setValue('');
                                                       App.filtro.getTrigger(0).hide();
                                                       App.GridClientes.getSelectionModel().deselectAll(); 
                                                       App.storeClientes.load();";
                            l.SpecialKey.Handler = @"if(e.getKey() == e.ENTER){
                                                        e.stopEvent();
                                                        App.GridClientes.getSelectionModel().deselectAll(); 
                                                        App.storeClientes.load();
                                                    }";
                        })
                )
        )
        .BottomBar(
            X.PagingToolbar()
                .DisplayInfo(true)
                .DisplayMsg("Mostrando clientes {0}-{1} de {2}")
                .EmptyMsg("No existen clientes")
        )
)
